<template>
  <div>
    <h1>添加页</h1>
    <div>
      <label class="sr-only">请输入品牌名称</label>
      <input type="text" @keyup.enter="add" v-model="brandName" class="form-control" placeholder="品牌名称">

      <button class="btn btn-default" @click.prevent="add">添加</button>
      <br></div>
  </div>
</template>

<script>
import axios from "axios"

export default {
  data() {
    return {
      brandName: ""
    };
  },
  methods: {
    add() {
      if (this.brandName.trim() == "") {
        alert("请输入品牌名称");
        return;
      }
      axios({
        url: "http://localhost:9999/api/addproduct",
        method: "post",
        data: { name: this.brandName }
      }).then(res => {
        this.brandName = "";
        //添加完成之后要进行页面的跳转
        // this.$route.push
        this.$router.push("/");
      });
    }
  }
};
</script>

<style>

</style>
